//
//  MQVistorTableViewController.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/13.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class MQVistorTableViewController: UITableViewController, MQVistorViewDelegate {
    
//    let userLogin:Bool = (MQUserAccountViewModel.shareUserAccountViewModel.userAccount?.access_token != nil)&&(!MQUserAccountViewModel.shareUserAccountViewModel.isExpiresIn)
    let userLogin:Bool = MQUserAccountViewModel.shareUserAccountViewModel.isUserLogin
    
    override func loadView() {
       setupUI()
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    //根据user的登录状态，选择界面view
    private func setupUI(){
        if userLogin == false{
            
//            loginView.backgroundColor = UIColor.redColor()
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginButtonDidClick")
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerButtonDidClick")
            
            view = loginView
            
            //代理
            loginView.delegate = self
            
            //抛出btn实现监听按钮点击事件
//            loginView.loginBtn.addTarget(self, action: "loginBtn", forControlEvents: UIControlEvents.TouchUpInside)
//            loginView.registerBtn.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
        }else{
            super.loadView()
        }
    }
    
    lazy var loginView:MQVistorView = MQVistorView()
    
    func loginButtonDidClick(){
        printfLog("登录")
        let vc = UINavigationController(rootViewController: MQOAuthViewController())
        navigationController?.presentViewController(vc, animated: true, completion: nil)

        
    }
    func registerButtonDidClick(){
        printfLog("注册")
    }
    
    
}
